package cn.fuxue.hrms.web.admin_controller;

import cn.fuxue.hrms.common.entity.Position;
import cn.fuxue.hrms.service.PositionService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("admin/positionController")
public class PositionController {
    @Autowired
    private PositionService positionService;

    @GetMapping("/selectAllPosition")
    public String selectAllPosition(Model model) {
        List<Position> positionList = positionService.selectAllPosition();
        model.addAttribute("positionList", positionList);
        return "admin/position";
    }

    @GetMapping("deleteByPrimaryKey/{Id}")
    public String deleteByPrimaryKey(@PathVariable Integer Id) {
         positionService.deleteByPositionId(Id);
         return "redirect:/admin/positionController/selectAllPosition";
    }


    @GetMapping("/findId")
    @ResponseBody
    public String findId(Model model) {
        return JSON.toJSONString(positionService.findId());
    }


}
